package com.xinzhitong.www.mapper;

import com.xinzhitong.www.pojo.Option;
import com.xinzhitong.www.pojo.TestHasQuestion;
import com.xinzhitong.www.pojo.TestInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 测试表相关操作
 *
 * @author 徐鑫 钟伟良 魏洛淳
 */
@Repository
public interface TestMapper {

    @Select("select * from test_view where credentialId=#{credentialId} and questionCount>0 ORDER BY RAND() LIMIT 1")
    TestInfo selectRandomTestInfoByCredential(Integer credentialId);

    @Select("select questionId from test_has_question_view where testId=#{testId} and type=#{type}")
    List<Integer> selectQuestionIdOfTestByType(@Param("testId") Integer testId, @Param("type") String type);

    @Select("select score from test_has_question where test_id = #{testId} and question_id = #{questionId}")
    TestHasQuestion selectQuestionScore(@Param("testId") Integer testId, @Param("questionId") Integer questionId);

    @Select("select text from question where id = #{questionId}")
    String selectQuestionText(@Param("questionId") Integer questionId);

    @Select("select `code`, text from `option` where question_id = #{questionId}")
    List<Option> selectOptionText(@Param("questionId") Integer questionId);

}
